<?
	include('top.php');
	include('conn.php');

	session_start();
	$msg='';
	if($_REQUEST['up']=='true' and isset($_REQUEST['name']))
	{
		$name=$_REQUEST['name'];
        mysql_set_charset('utf8');
		$sqledit="select * from usermast where status=0 and user_id='".$name."'";
		$resedit=mysql_query($sqledit);
		$rowedit=mysql_fetch_assoc($resedit);		
	}
	if($_REQUEST['submit']=='Update')
	{
		$user_name=$_REQUEST['user_name'];
		$user_id=$_REQUEST['user_id'];
        $usergroup=$_REQUEST['usergroup'];
		$email_id=$_REQUEST['email_id'];
        $modifiedby=$_SESSION['username'];
        $id=$_REQUEST['id'];
				
		$sql="update usermast set user_name='".$user_name."',
                                  user_id='".$user_id."',
                                  usergroup='".$usergroup."',
                                  email_id='".$email_id."', 
                                  modifiedby='".$modifiedby."'  where id = $id";
		$res=mysql_query($sql);
		if($res)
		{
			 echo "<script>window.location.href = 'adduser.php'</script>";
		}	
		else
		{
			$msg='Updation Failed';			
		}
	}	
?>
<div  align="center">
			<div ng-controller="SearchCtrl">
			<form name="adduseredit" action="adduseredit.php" method="post">
			<input type="hidden" name="id" id="id" value="<?=$rowedit['id']?>" />
			<table  cellpadding="4" id="box-table-a" cellspacing="4" border="1" width="650" bgcolor="#000000" style="background-color:#DFEBF9;">
				<tr><td colspan="3" align="center" style="text-align:center; color:#FF0000;"><?=$msg?></td></tr>
				<tr>
				  <td colspan="3" align="center" style="text-align:center; font-weight:bold;">User Master (Edit)</td>
				</tr>
				<tr bgcolor="#FFFFFF">
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Name</label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
					<input type="text" id="user_name" name="user_name" class="smallInput" required= "" value="<?=$rowedit['user_name']?>" ng-model="user_name" placeholder="Name" style="width:280px; text-align:left; font-size:12px; font-weight:bold;" />
					</td>
				</tr>
				<tr bgcolor="#FFFFFF">
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">User Id</label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
					<input type="text" id="user_id" name="user_id" class="smallInput" required= "" value="<?=$rowedit['user_id']?>" ng-model="user_id" placeholder="UserId" style="width:280px; text-align:left; font-size:12px; font-weight:bold;" />
					</td>
				</tr>
				<tr bgcolor="#FFFFFF">
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Email Id</label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<input type="text" id="email_id" name="email_id" class="smallInput" required= "" ng-model="email_id" placeholder="Email" value="<?=$rowedit['email_id']?>" style="width:180px; text-align:left; font-size:12px; font-weight:bold;" />
					</td>
				</tr>
                
                <tr bgcolor="#FFFFFF">
    				<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">User Group <br />
					</label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
				
                <select name="usergroup" id="usergroup" class="smallInput" required= "" ng-model="usergroup" placeholder="usergroup" value="<?=$rowedit['usergroup']?>" style="width:280px; text-align:left; font-size:12px; font-weight:bold;" />
		        	<?
                            $ug1='';
							$ug2='';
							if ($rowedit['usergroup']=='OPSUSER')
								$ug1='selected="selected"';
							if ($rowedit['usergroup']=='ADMIN')
								$ug2='selected="selected"';	
					?>
                    <option <?=$ug1?>>OPSUSER</option>
    				<option <?=$ug2?>>ADMIN</option>
				</select>
                </td>
                 </tr>                
				<tr>
					<td align="center" colspan="3" style="background-color:#BBE2EE">
					<button type="submit" class="btn" name="submit" value="Update">Update</button>
					</td>
				</tr>
			</table>
			</form>
		</div>
			
</div>
</body>
</html>
